package top.superflow.service.view.utils

import top.superflow.lang.CollectionUtils
import top.superflow.service.view.dto.ColumnDef

object ViewColumnUtils {

  final val FIRST_CLASS_ORDER = -1 * 10000

  final val SECOND_CLASS_ORDER = -1 * 1000

  final val THIRD_CLASS_ORDER = -1 * 100



  private val predefinedOrders = Map[String, Int](("key", FIRST_CLASS_ORDER), ("group", SECOND_CLASS_ORDER),("alias", THIRD_CLASS_ORDER))

  def setOrderForCommonColumns(columns : List[ColumnDef]): Unit ={
    if(CollectionUtils.isEmpty(columns)){
      return;
    }

    for(column <- columns){
      val predefinedOrder = predefinedOrders.get(column.getHeaderName)
      if(!predefinedOrder.isEmpty){
        column.setDisplayOrder(predefinedOrder.get)
      }
    }
  }

  def setPredefinedViewConf(columns : List[ColumnDef]): Unit ={
    if(CollectionUtils.isEmpty(columns)){
      return;
    }

    for(column <- columns){
      //TODO: define the width etc somewhere to make sure the column be displayed well
    }
  }
}
